package com.nf1000.balancelibrary;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;

import java.util.UUID;

/**
 * Created by Jason on 2016/3/22.
 */
public class BluetoothTools {

    private static BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    public static final UUID PRIVATE_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
    public static final String DEVICE = "DEVICE";
    public static final String SERVER_INDEX = "SERVER_INDEX";
    public static final String DATA = "DATA";
    public static final String ACTION_READ_DATA = "ACTION_READ_DATA";
    public static final String ACTION_NOT_FOUND_SERVER = "ACTION_NOT_FOUND_DEVICE";
    public static final String ACTION_START_DISCOVERY = "ACTION_START_DISCOVERY";
    public static final String ACTION_FOUND_DEVICE = "ACTION_FOUND_DEVICE";
    public static final String ACTION_SELECTED_DEVICE = "ACTION_SELECTED_DEVICE";
    public static final String ACTION_START_SERVER = "ACTION_STARRT_SERVER";
    public static final String ACTION_STOP_SERVICE = "ACTION_STOP_SERVICE";
    public static final String ACTION_DATA_TO_SERVICE = "ACTION_DATA_TO_SERVICE";
    public static final String ACTION_DATA_TO_GAME = "ACTION_DATA_TO_GAME";
    public static final String ACTION_CONNECT_SUCCESS = "ACTION_CONNECT_SUCCESS";
    public static final String ACTION_CONNECT_ERROR = "ACTION_CONNECT_ERROR";
    public static final int MESSAGE_CONNECT_SUCCESS = 2;
    public static final int MESSAGE_CONNECT_ERROR = 3;
    public static final int MESSAGE_READ_OBJECT = 4;
    public static final String BluetoothAddress = "5C:DA:D4:1C:AB:36";
    public static final String BluetoothAddress2 = "04:18:0F:30:A8:70";

    public BluetoothTools() {
    }

    public static void openBluetooth() {
        adapter.enable();
    }

    public static void closeBluetooth() {
        adapter.disable();
    }

    public static void openDiscovery(int duration) {
        if(duration <= 0 || duration > 300) {
            duration = 200;
        }

        Intent intent = new Intent("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE");
        intent.putExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION", duration);
    }

    public static void stopDiscovery() {
        adapter.cancelDiscovery();
    }
}
